package com.freedom.pms.goods.interfaces.controller.admin;

import com.freedom.common.core.result.CommonResult;
import com.freedom.common.core.result.PageResult;
import com.freedom.pms.goods.application.service.cmd.GoodsSpuCmdService;
import com.freedom.pms.goods.application.service.query.GoodsSpuQueryService;
import com.freedom.pms.goods.infrastructure.persistence.pojo.command.AdminSpuCommand;
import com.freedom.pms.goods.infrastructure.persistence.pojo.query.AdminSpuPageQuery;
import com.freedom.pms.goods.infrastructure.persistence.pojo.vo.AdminGoodsSpuDetailVO;
import com.freedom.pms.goods.infrastructure.persistence.pojo.vo.AdminGoodsSpuPageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

@Api(tags = "「管理端」商品管理")
@RestController
@RequestMapping("/api/goods/spu")
@RequiredArgsConstructor
public class AdminSpuController {

    private final GoodsSpuQueryService goodsSpuQueryService;

    private final GoodsSpuCmdService goodsSpuCmdService;

    @ApiOperation(value = "商品分页列表")
    @GetMapping("/page")
    public PageResult<AdminGoodsSpuPageVO> queryAdminGoodsSpuPage(@Validated AdminSpuPageQuery queryParams) {
        return PageResult.success(goodsSpuQueryService.queryAdminGoodsSpuPage(queryParams));
    }

    @ApiOperation(value = "商品详情")
    @GetMapping("/{id}")
    public CommonResult<AdminGoodsSpuDetailVO> findAdminDetail(@NotNull(message = "参数非法") @PathVariable Integer id) {
        return CommonResult.success(goodsSpuQueryService.findAdminDetail(id));
    }

    @ApiOperation(value = "新增商品")
    @PostMapping
    public CommonResult<Boolean> addGoodsSpu(@RequestBody @Validated AdminSpuCommand command) {
        return CommonResult.success(goodsSpuCmdService.addGoodsSpu(command));
    }

    @ApiOperation(value = "修改商品")
    @PutMapping("/{id}")
    public CommonResult<Boolean> modifyGoodsSpu(@NotNull(message = "参数非法") @PathVariable Integer id, @RequestBody  @Validated AdminSpuCommand command) {
        return CommonResult.success(goodsSpuCmdService.modifyGoodsSpu(id, command));
    }

//    @ApiOperation(value = "上架商品")
//    @PutMapping("/up/{id}")
//    public CommonResult<Boolean> upSpu(@NotNull(message = "参数非法") @PathVariable Integer id) {
//        return CommonResult.success(goodsSpuCmdService.upSpu(id));
//    }
//
//    @ApiOperation(value = "下架商品")
//    @PutMapping("/down/{id}")
//    public CommonResult<Boolean> downSpu(@NotNull(message = "参数非法") @PathVariable Integer id, @RequestParam String downMessage) {
//        return CommonResult.success(goodsSpuCmdService.downSpu(id, downMessage));
//    }
}

